package com.github.tiger.gateway;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@EnableDiscoveryClient
@RestController
public class TigerGatewayApplication {

    public static void main(String[] args) {
        SpringApplication.run(TigerGatewayApplication.class, args);
    }

    /**
     * 配置健康检查路径
     * @return
     */
    @GetMapping("/")
    public String get() {
        return "haha";
    }

    @GetMapping("/hystrixTimeout")
    public String timeOut() {
        return "超时了";
    }


    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                //basic proxy
                .route(r -> r.path("/baidu")
                        .uri("http://baidu.com:80/")
                ).build();
    }
}
